<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>注册 - 个人博客系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" href="../../static/layui/css/admin.css" media="all" th:href="@{/layui/css/admin.css}">
    <link rel="stylesheet" href="../../static/layui/css/login.css" media="all" th:href="@{/layui/css/login.css}">
</head>
<body>


<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>个人博客注册页面</h2>
            <font style="color: red"></font>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone"
                       for="LAY-user-login-email"></label>
                <input type="text" name="email" id="LAY-user-login-email" placeholder="邮箱"
                       class="layui-input">
                <div id="email_check"></div>
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password"
                       placeholder="密码" class="layui-input">
                <div id="password_check"></div>
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-repass"></label>
                <input type="password" name="repass" id="LAY-user-login-repass"
                       placeholder="确认密码" class="layui-input">
                <div id="repass_check"></div>
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                       for="LAY-user-login-nickname"></label>
                <input type="text" name="nickname" id="LAY-user-login-nickname"
                       placeholder="昵称" class="layui-input">
                <div id="nickname_check"></div>
            </div>
            <div class="layui-form-item">
                <button type="submit" id="register_byn" class="layui-btn layui-btn-fluid" lay-submit=""
                        lay-filter="LAY-user-reg-submit">注 册
                </button>
            </div>
            <div class="layui-trans layui-form-item layadmin-user-login-other">
                <!--<label>社交账号注册</label>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>-->
                <a href="/" th:href="@{/}" style="float: left"
                   class="layadmin-user-jump-change layadmin-link layui-hide-xs">返回首页</a>

                <a href="login.html" th:href="@{/user/login}"
                   class="layadmin-user-jump-change layadmin-link layui-hide-xs">用已有帐号登入</a>
            </div>
        </div>
    </div>


</div>

<script src="../../static/layui/layui.js" th:src="@{/layui/layui.js}"></script>
<script src="../../static/js/jquery-1.8.3.min.js" th:src="@{/js/jquery-1.8.3.min.js}"></script>
<script type="text/javascript" th:inline="javascript">

    $(function () {
        if ("adsd".indexOf("f") != -1){
            alert(1);
        }
    });

    function checkEmail() {
        //1.定义正则表达式
        var pattern = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
        //2.获取员工姓名
        var email = $("#LAY-user-login-email").val();
        //3.判断 给出提示信息
        var flag = pattern.test(email);
        if (!flag) {
            //不合法
            $("#email_check").html('<i style="color: red" class="layui-icon layui-icon-close"></i><span\n' +
                '                            style="color: red;">邮箱格式不正确</span>')
        } else {
            //合法
            $("#email_check").html('<i style="color: green" class="layui-icon layui-icon-ok"></i><span\n' +
                '                            style="color: green;">邮箱格式正确</span>');
        }

        return flag;
    }

    function checkPassword() {
        var pattern = /^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,20}$/;
        var password = $("#LAY-user-login-password").val();
        var flag = pattern.test(password);
        if (!flag) {
            //不合法
            $("#password_check").html('<i style="color: red" class="layui-icon layui-icon-close"></i><span\n' +
                '                            style="color: red;">请输入6-20位数字,字母,特殊字符中两种组合</span>')
        } else {
            //合法
            $("#password_check").html('<i style="color: green" class="layui-icon layui-icon-ok"></i><span\n' +
                '                            style="color: green;">密码格式正确</span>');
        }

        return flag;
    }

    function checkRepass() {
        var pattern = /^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,20}$/;
        var repass = $("#LAY-user-login-repass").val();
        var password = $("#LAY-user-login-password").val();
        var flag = pattern.test(repass);
        if (!flag) {
            //不合法
            $("#repass_check").html('<i style="color: red" class="layui-icon layui-icon-close"></i><span\n' +
                '                            style="color: red;">请输入6-20位数字,字母,特殊字符中两种组合</span>')
        } else {
            //合法
            if (repass == password) {
                $("#repass_check").html('<i style="color: green" class="layui-icon layui-icon-ok"></i><span\n' +
                    '                            style="color: green;">确定密码正确</span>');
            } else {
                $("#repass_check").html('<i style="color: red" class="layui-icon layui-icon-close"></i><span\n' +
                    '                            style="color: red;">两次密码不一致</span>')
            }

        }

        return flag;
    }

    function checkNickName() {
        //1.定义正则表达式 不可全为空格和换行，允许字符前面和后面为空
        var pattern = /^[\s\S]*.*[^\s][\s\S]*$/;
        //2.获取员工姓名
        var nickname = $("#LAY-user-login-nickname").val();
        //3.判断 给出提示信息
        var flag = pattern.test(nickname);
        if (!flag) {
            //不合法
            $("#nickname_check").html('<i style="color: red" class="layui-icon layui-icon-close"></i><span\n' +
                '                            style="color: red;">昵称不能为空</span>')
        } else {
            //合法
            $("#nickname_check").html('<i style="color: green" class="layui-icon layui-icon-ok"></i><span\n' +
                '                            style="color: green;">昵称格式正确</span>');
        }

        return flag;
    }


    $("#LAY-user-login-email").blur(checkEmail);
    $("#LAY-user-login-password").blur(checkPassword);
    $("#LAY-user-login-repass").blur(checkRepass);
    $("#LAY-user-login-nickname").blur(checkNickName);


    layui.use(['element', 'form', 'jquery','layer'], function () {
        var element = layui.element;
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        var $ = layui.jquery;
        var layer = layui.layer;
        form.on('submit(LAY-user-reg-submit)', function (data) {
            var c1 = checkEmail();
            var c2 = checkPassword();
            var c3 = checkRepass();
            var c4 = checkNickName();
            if (c1 && c2 && c3 && c4) {
                $("#register_byn").html('<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>');
                $.post(/*[[@{/user/register}]]*/"http://localhost:8081/user/register", data.field, function (data) {
                    if (data.flag) {
                        $("#register_byn").html("注 册");
                        var em = $("#LAY-user-login-email").val();
                        if (em.indexOf("qq.com") != -1) {
                            if (confirm("注册成功，是否前往QQ邮箱激活？")) {
                                location.href = "https://mail.qq.com/";
                            }
                        } else if (em.indexOf("163.com") != -1) {
                            if (confirm("注册成功，是否前往163邮箱激活？")) {
                                location.href = "https://mail.163.com/";
                            }
                        } else if (em.indexOf("aliyun.com") != -1) {
                            if (confirm("注册成功，是否前往阿里云邮箱激活？")) {
                                location.href = "https://mail.aliyun.com/";
                            }
                        } else {
                            if (confirm("注册成功，记得前往邮箱激活，是否前往登录页面？")) {
                                location.href = /*[[@{/user/login}]]*/"http://localhost:8081/user/login";
                            }
                        }

                    } else {
                        $("#register_byn").html("注 册");
                        layer.msg(data.reg_error);
                    }

                })
            } else {
                return false;
            }


        });
        //……

        //但是，如果你的HTML是动态生成的，自动渲染就会失效
        //因此你需要在相应的地方，执行下述方法来手动渲染，跟这类似的还有 element.init();
        form.render();//在最后添加这句代码
    });
</script>
</body>
</html>